package com.catering.common.seller.aop;


import com.catering.common.seller.context.SellerContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * 忽略多店铺的 Aspect，基于 {@link IgnoreSeller} 注解实现，用于一些全局的逻辑。
 *
 * @author Administrator
 * @date 2023/02/24
 */
@Aspect
@Slf4j
public class SellerIgnoreAspect {

    @Around("@annotation(sellerIgnore)")
    public Object around(ProceedingJoinPoint joinPoint, IgnoreSeller sellerIgnore) throws Throwable {
        Boolean oldIgnore = SellerContextHolder.isIgnore();
        try {
            SellerContextHolder.setIgnore(true);
            // 执行逻辑
            return joinPoint.proceed();
        } finally {
            SellerContextHolder.setIgnore(oldIgnore);
        }
    }

}
